<?php

/**
 * Desc
 * @description Holp You Do Good But Not Evil
 * @copyright   Copyright 2014-2015 <ycchen@iwshop.cn>
 * @license     LGPL (http://www.gnu.org/licenses/lgpl.html)
 * @author      Chenyong Cai <ycchen@iwshop.cn>
 * @package     Wshop
 * @link        http://www.iwshop.cn
 */
class mInCome extends Model {


    /**
    * 增加一条分享记录
    */
    public function createInCome($total_money,$offline_money,$online_money,$real_money,$des,$time){
    
  
      $id = $this->Dao->insert('income', '`total_money`,`online_money`,`offline_money`,`real_money`,`add_time`,`des`')
                        ->values(array($offline_money,$offline_money,$online_money,$real_money,$time,$des))->exec();
      return $id;
    }
    
    public function updateInCome($id,$data = array()){
     
       return $this->Dao->update('income')->set($data)->where("id =".$id)->exec(); 
     
    }
    
   public function get_inCome_byId($id){
     
       $SQL = sprintf("SELECT * FROM income where id =".$id);
       return  $this->Db->getOneRow($SQL);
   }
    
   public function get_income_list($where='',$orderby='add_time desc',$offset,$pageSize){
    
    	$list = array();
 
    	if($offset>=0){
	    	$list = $this->Dao->select()->from('income')->where($where)->orderby($orderby)->limit("$offset,$pageSize")->exec(false);
    	}else{
    		$list = $this->Dao->select()->from('income')->where($where)->orderby($orderby)->exec(false);
    	}
    
    	return $list;
    }
    
    
    public function sumTotal(){

        $mSql = sprintf("select date_format(from_unixtime(`add_time`),'%y-%m') AS `add_time` ,sum(total_money) as money   from income GROUP BY date_format(from_unixtime(`add_time`),'%y-%m');");
        return $this->Db->query($mSql);
    }
  
    
}
